import { Matrix4 } from "three";
import GameObject from "../gameObject/GameObject";
import Geo from "../gameObject/Geo";
import Mat from "../gameObject/Mat";
import Mesh from "./Mesh";

export default class Box extends Mesh {

    public r: number;

    public constructor(name: string, r: number = 0.4) {

        const vertices = [
            -r, r, -r,
            -r, r, r,
            r, r, r,
            r, r, -r,
            -r, -r, -r,
            -r, -r, r,
            r, -r, r,
            r, -r, -r,

        ];

        const normals = [
            -1, 1, -1,
            -1, 1, 1,
            1, 1, 1,
            1, 1, -1,
            -1, -1, -1,
            -1, -1, 1,
            1, -1, 1,
            1, -1, -1,
        ];

        const elements = [
            0, 1, 2, 0, 2, 3,
            1, 5, 6, 1, 6, 2,
            5, 4, 7, 5, 7, 6,
            4, 0, 3, 4, 3, 7,
            2, 6, 7, 2, 7, 3,
            0, 4, 5, 0, 5, 1,
        ];

        const mat = new Mat({
            program: 'color',
            mode: ['TRIANGLES'],
            data: {
                'u_PointSize': { type: 'uniform1f', value: 10 },
                'u_PvM4': { type: 'uniformMatrix4fv', value: new Matrix4().elements },
                'u_ModelM4': { type: 'uniformMatrix4fv', value: new Matrix4().elements },
            },
        });

        const geo = new Geo({
            data: {
                'a_Position': { size: 3, array: new Float32Array(vertices) },
            },
            element: { array: new Uint16Array(elements) }
        });


        super(name, { geo: geo, mat: mat });
        this.r = r;
    }



}